#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Author  :   JingV
@Version :   1.0
@Contact :   None
@License :   None
@Desc    :   None
'''


class Solution(object):
    def plusOne(self, digits):
        len_digits, flag = len(digits), 0
        for i in range(len_digits - 1, -1, -1):
            if i == len_digits -1:
                temp = digits[i] + 1 + flag
            else:
                temp = digits[i] + flag
            if temp < 10:
                digits[i], flag = temp, 0
                break
            else:
                digits[i], flag = temp - 10, 1
        return digits if flag == 0 else [1] + digits


def main():
    solution = Solution()
    tests = [
        [9, 9],
        [1, 2, 3],
        [1, 2, 9],
        [9],
    ]
    for digits in tests:
        print(solution.plusOne(digits))


if __name__ == "__main__":
    main()
